<template>
    <header class="learning-header">
        <div class="header-container">
            <div class="header-logo">
                <!--                 :style="{color: colors[i]}"-->
                <span v-for="(str,i) in logo" :key="i">{{ str }}</span>
            </div>
            <div class="header-content">

                <div class="theme-toggle-content">
                    <swatch v-model="darkTheme"></swatch>
                </div>
            </div>
        </div>
    </header>
</template>

<script setup>
import { ref, watch } from 'vue';
import Swatch from '@/components/swatch/swatch.vue';
import { getStorage, setStorage } from '@/assets/js/utils';
import { useListenerStorage } from '@/assets/js/hooks';

const logo = ref('Learning');
const darkTheme = ref(getStorage('theme') === 'dark');

watch(darkTheme, (val) => {
  setStorage('theme', val ? 'dark' : 'light');
  document.documentElement.setAttribute('theme', val ? 'dark' : 'light');
}, { immediate: true });
useListenerStorage('theme', (e) => {
  darkTheme.value = e.newValue === 'dark';
});
// eslint-disable-next-line max-len
// const colors = ref([ '#c45656', '#f89898', '#337ecc', '#79bbff', '#529b2e', '#95d475', '#b88230', '#eebe77' ]);
</script>

<style scoped lang="scss">
.learning-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--learning-header-height);
  border-bottom: 1px solid var(--learning-border-color);
  padding: 0 12px 0 24px;
  background-image: radial-gradient(transparent 1px, var(--learning-bg-color-1) 1px);
  background-size: 4px 4px;
  backdrop-filter: saturate(50%) blur(4px);
  -webkit-backdrop-filter: saturate(50%) blur(4px);

  .header-container {
    margin: 0 auto;
        display: flex;
        justify-content: space-between;
        width: 100%;
        height: 100%;

        .header-logo {
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 20px;
            font-weight: 600;
            color: var(--learning-color-1);
        }

    .header-content {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        flex-grow: 1;
        .theme-toggle-content{
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }
  }

  @media screen and (min-width: 1440px) {
    .header-container {
        max-width: calc(var(--vp-screen-max-width))
    }
  }
}

.learning-header {
    top: 0;
    left: 0;
    position: relative;
}

@media screen and (min-width: 768px) {
    .learning-header {
        padding: 0 12px 0 32px
    }
}

@media screen and (min-width: 1280px) {
    .learning-header {
        padding: 0 32px
    }
}

@media screen and (min-width: 960px) {
  .learning-header {
    position: sticky;
    width: 100%
  }
}
</style>
